import {ModuleBase} from "./ModuleBase";
import {ConstVariable} from "../support/ConstVariable";
import jQuery from 'jquery';

class CommonClass extends ModuleBase {
    constructor(clazz, interfaceObj) {
        super(clazz, interfaceObj);
    }

    /**
     * 模块加载的入口
     */
    run(...args) {
        super.run(args);
        //处理样式库
        super._loadStyleLibrary();
        let deferred = jQuery.Deferred().resolve(), langSet = {};
        return deferred.then(() => {
            //加载多语言信息
            return super._loadI18nResource(langSet);
        }).then(() => {
            return this.$launch({lang: langSet});
        }).done(() => {
            this.Logger.info("launch presenter complete!");
        });
    }

    destroy() {
        super._releaseStyleLibrary();
        super.destroy();
    }

    setModuleSkin(skin) {
        if (this.metaInfo.type === ConstVariable.PresenterType.LAUNCHER) {
            if (window.Midware.styleManager) {
                Midware.styleManager.changeStyle(this.metaInfo.name, this._app, skin, this.Language);
            }
        }
    }

    get ComponentLoader() {
        if (this.metaInfo.type !== ConstVariable.PresenterType.LAUNCHER || !this.loader) {
            throw new Error('current module is not Launcher!!');
        }
        return this.loader;
    }
}

export {CommonClass};